package com.example.commons.launcher.impl;

import com.example.commons.constant.LauncherConstant;
import com.example.commons.launcher.LauncherService;
import lombok.NoArgsConstructor;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.stereotype.Component;

import java.util.Properties;

/**
 * @author whx
 * @date 2022/4/12
 */
public class NacosLauncherServiceImpl implements LauncherService {
    @Override
    public void launcher(SpringApplicationBuilder builder, String applicationName, String profile, boolean isLocalDev){
        Properties props = System.getProperties();
        // 通用注册
        props.setProperty("spring.cloud.nacos.discovery.server-addr", LauncherConstant.nacosAddr(profile));
        props.setProperty("spring.cloud.nacos.config.server-addr", LauncherConstant.nacosAddr(profile));
        props.setProperty("spring.cloud.nacos.config.username", LauncherConstant.NACOS_USERNAME);
        props.setProperty("spring.cloud.nacos.config.password", LauncherConstant.NACOS_PASSWORD);
        props.setProperty("spring.cloud.nacos.discovery.username", LauncherConstant.NACOS_USERNAME);
        props.setProperty("spring.cloud.nacos.discovery.password", LauncherConstant.NACOS_PASSWORD);
        props.setProperty("spring.cloud.nacos.config.file-extension", "yaml");
        props.setProperty("spring.cloud.nacos.config.shared-configs[0].data-id", LauncherConstant.sharedDataId());
        props.setProperty("spring.cloud.nacos.config.shared-configs[0].group", "DEFAULT_GROUP");
        props.setProperty("spring.cloud.nacos.config.shared-configs[0].refresh", "true");
        props.setProperty("spring.cloud.nacos.config.shared-configs[1].data-id", LauncherConstant.sharedDataId(profile));
        props.setProperty("spring.cloud.nacos.config.shared-configs[1].group", "DEFAULT_GROUP");
        props.setProperty("spring.cloud.nacos.config.shared-configs[1].refresh", "true");
    }
}
